import { View } from "../../../mvc/core/View";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Language } from "../../../../extend/language/Language";
import { ResFileConst } from "../../resource/ResFileConst";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { IllustrateState } from "./IllustrateState";
import { IllustratePieceInfo } from "./IllustratePieceInfo";
import { ItemData } from "../../resource/info/ItemData";
import { ColorConfig } from "../../resource/ColorConfig";
import { LoaderManager } from "../../../../com/gengine/resource/LoaderManager";
import { LoaderPriority } from "../../../../com/gengine/resource/LoaderPriority";
import { TItemWeapon } from "../../../../Message/Db/Tables/TItemWeapon";
import { EquipmentItemDataUtil } from "../common/EquipmentItemDataUtil";
import { Cache } from "../../cache/Cache";
import { EquipmentUtil } from "../common/util/EquipmentUtil";
import { ImageInfo } from "../../../../com/gengine/resource/info/ImageInfo";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
type int = number;
//class IllustratePicecePanel
    
    export  class IllustratePicecePanel extends View
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(0, 0, 160, 394, this);
            ObjCreate.createBg(20, 38, 120, 2, this, ImagesConst.SplitLine);
            ObjCreate.createBg(20, 345, 120, 2, this, ImagesConst.SplitLine);
            this._headBg = new Object /* flash.display.Bitmap */();
            this._headBg.x = 3;
            this._headBg.y = 275;
            addChild(this._headBg);
            this._headBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.RbListHeader);
            var loc1=new GTextFormat(FontUtil.stXingkaiName, 18, 15788607, null, null, null, null, null, flash.text.TextFormatAlign.CENTER);
            this._nameTxt = ObjCreate.createGTextField("", 0, 15, 157, 30, this, loc1);
            var loc2=GlobalStyle.textFormat6;
            loc2.size = 18;
            loc2.font = FontUtil.EmbedTitleName;
            ObjCreate.createEmbedTextFiled(Language.getString(36303), 2, 278, 155, 30, this, GlobalStyle.getTextFormatCenter(loc2));
            this._itemBmp = new Object /* flash.display.Bitmap */();
            this._itemBmp.x = 34;
            this._itemBmp.y = 48;
            addChild(this._itemBmp);
            this._cardBmp = new Object /* flash.display.Bitmap */();
            this._cardBmp.x = 27;
            this._cardBmp.y = 42;
            addChild(this._cardBmp);
            this._equipBmp = new Object /* flash.display.Bitmap */();
            this._equipBmp.x = 100;
            this._equipBmp.y = 300;
            addChild(this._equipBmp);
            this._descTxt = ObjCreate.createGTextField("", 10, 185, 150, 100, this, GlobalStyle.setTextFormatLeading(GlobalStyle.textFormat1, 3));
            this._descTxt.wordWrap = true;
            this._descTxt.multiline = true;
            this._curReward = ObjCreate.createGTextField("", 15, 305, 170, 60, this, GlobalStyle.setTextFormatLeading(GlobalStyle.textFormat6, 5));
            this._curReward.wordWrap = true;
            this._curReward.multiline = true;
            this._nextReward = ObjCreate.createGTextField("", 15, 350, 170, 60, this, GlobalStyle.setTextFormatLeading(GlobalStyle.textFormat6, 5));
            this._nextReward.wordWrap = true;
            this._nextReward.multiline = true;
            this._cardBtn = ObjCreate.createGLoadedButton(ResFileConst.illustrateCardBtn, 27, 42, 113, 146, this);
            this._cardBtn.visible = false;
            this._activeBtn = ObjCreate.createGLoadedButton(ResFileConst.illustrateActiveBtn, 54, 42, 86, 90, this);
            this._activeBtn.visible = false;
            LoaderHelp.addResCallBack(ResFileConst.Illustrate, this.onResLoaded);
            return;
        }

        /* internal  */onResLoaded(): void
        {
            this._cardBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.illustrateCardBg);
            this._headBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.titleBottomBg);
            if (this._pieceInfo && !(this._pieceInfo.state == IllustrateState.IllustrateNotActive) && !(this._pieceInfo.state == IllustrateState.IllustrateCanActiveBlue)) 
            {
                this._equipBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.activeHad);
            }
            else 
            {
                this._equipBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.avtiveNon);
            }
            return;
        }

        public updatePieceInfo(arg1: IllustratePieceInfo): void
        {
            var loc1=0;
            var loc2=null;
            var loc3=null;
            this._pieceInfo = arg1;
            this._itemBmp.bitmapData = null;
            this._descTxt.htmlText = "";
            if (arg1) 
            {
                LoaderHelp.addResCallBack(ResFileConst.Illustrate, this.onResLoaded);
                loc1 = arg1.code;
                loc2 = [];
                if (loc1 != 0) 
                {
                    this._itemData = new ItemData(loc1);
                    loc3 = ColorConfig.instance.getItemColor(this._itemData.itemInfo.item.color).color;
                    this._nameTxt.htmlText = "<font color=\'" + loc3 + "\'>" + this._itemData.itemInfo.item.name + "</font>";
                    loc2 = this._itemData.itemInfo.item.descStr.split("$");
                    if (loc2 && loc2[1]) 
                    {
                        this._descTxt.htmlText = "<font color=\'#b1efff\'>" + loc2[1] + "</font>";
                    }
                    this.updateAttrbute(this._itemData, 0, 0, 0);
                    LoaderManager.instance.load(this._itemData.itemInfo.item.effectEx + ".jpg", this.onLoadCompleteHandler, LoaderPriority.LevelB);
                }
                if (this._pieceInfo.state != IllustrateState.IllustrateCanActiveBlue) 
                {
                    if (this._pieceInfo.state != IllustrateState.IllustrateNotActive) 
                    {
                        this._cardBtn.visible = false;
                        this._activeBtn.visible = false;
                    }
                    else 
                    {
                        this._cardBtn.visible = true;
                        this._activeBtn.visible = false;
                    }
                }
                else 
                {
                    this._cardBtn.visible = true;
                    this._activeBtn.visible = true;
                }
            }
            return;
        }

        public activePiece(): void
        {
            this._cardBtn.visible = false;
            this._activeBtn.visible = false;
            LoaderHelp.addResCallBack(ResFileConst.Illustrate, this.onActResLoaded);
            return;
        }

        /* internal  */onActResLoaded(): void
        {
            this._equipBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.activeHad);
            return;
        }

        /* internal  */updateAttrbute(arg1: ItemData, arg2: int, arg3: int, arg4: int): void
        {
            var loc3=null;
            var loc4=0;
            var loc7=null;
            var loc8=null;
            this._curReward.htmlText = "";
            this._nextReward.htmlText = "";
            var loc1=ColorConfig.instance.getItemColor(this._itemData.itemInfo.item.color).color;
            var loc2=this.getAttributeByItemData(arg1);
            var loc5="";
            loc4 = 0;
            while (loc4 < loc2.length) 
            {
                loc3 = loc2[loc4];
                loc5 = loc5 + "<font color=\'" + loc1 + "\'>" + loc3.name + "+\t" + loc3.value + "</font>\n";
                ++loc4;
            }
            this._curReward.htmlText = Language.getStringByParam(36304, loc1) + loc5;
            var loc6;
            if ((loc6 = (arg1.itemInfo.extend as TItemWeapon).attackSpeed) != 0) 
            {
                loc5 = "";
                loc7 = new ItemData(loc6);
                loc8 = ColorConfig.instance.getItemColor(loc7.itemInfo.item.color).color;
                loc2 = this.getAttributeByItemData(loc7);
                loc4 = 0;
                while (loc4 < loc2.length) 
                {
                    loc3 = loc2[loc4];
                    loc5 = loc5 + "<font color=\'" + loc8 + "\'>" + loc3.name + "+\t" + loc3.value + "</font>\n";
                    ++loc4;
                }
                this._nextReward.htmlText = Language.getString(36314) + "\n<font color=\'" + loc8 + "\'>" + loc5 + "</font>";
            }
            return;
        }

        /* internal  */getAttributeByItemData(arg1: ItemData): Array<any>
        {
            var loc4=null;
            var loc6=0;
            var loc1=[];
            var loc2=new EquipmentItemDataUtil(arg1);
            var loc3=loc2.getAddtionalArray();
            var loc5=new Map<any, any> /* flash.utils.Dictionary */();
            while (loc6 < loc3.length) 
            {
                loc4 = loc3[loc6];
                loc5[loc4["addition"]] = loc4["value"];
                ++loc6;
            }
            var loc7=Cache.instance.role.entityInfo.career;
            loc1 = EquipmentUtil.getSelfCareerAttribute(loc7, loc5);
            return loc1;
        }

        /* internal  */onLoadCompleteHandler(arg1: ImageInfo): void
        {
            this._itemBmp.bitmapData = arg1.bitmapData;
            return;
        }

        /* internal */ /* var */_cardBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_equipBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_itemBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_headBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_itemData: ItemData;

        /* internal */ /* var */_nameTxt: GTextFiled;

        /* internal */ /* var */_descTxt: GTextFiled;

        /* internal */ /* var */_curReward: GTextFiled;

        /* internal */ /* var */_nextReward: GTextFiled;

        /* internal */ /* var */_pieceInfo: IllustratePieceInfo;

        /* internal */ /* var */_cardBtn: GLoadedButton;

        /* internal */ /* var */_activeBtn: GLoadedButton;
    }
